package com.arcaneshift.model.action.game;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.arcaneshift.model.abstracts.AbstractArenaObject;

public class ArenaMap implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private List<List<AbstractArenaObject>> matrix;
	
	public ArenaMap(int x, int y) {
		matrix = new ArrayList<List<AbstractArenaObject>>();
		
		for (int i = 0; i < x; i++) {
			List<AbstractArenaObject> arenaLine = new ArrayList<AbstractArenaObject>();
			
			for (int j = 0; j < y; j++) {
				arenaLine.add(null);
			}
			
			matrix.add(arenaLine);
		}
	}
	
	public void set(int x, int y, AbstractArenaObject item) {
		if (x < matrix.size()) {
			if (y < matrix.get(x).size()) {
				matrix.get(x).set(y, item);
			}
		}
	}
	
	public List<List<AbstractArenaObject>> get() {
		return matrix;
	}
	
	public AbstractArenaObject get(int x, int y) {
		if (x < matrix.size()) {
			if (y < matrix.get(x).size()) {
				return matrix.get(x).get(y);
			}
		}
		
		return null;
	}
	
	public String toLogicString() {
		StringBuilder builder = new StringBuilder();
		
		for (int i = 0; i < matrix.size(); i++) {
			for (int j = 0; j < matrix.get(i).size(); j++) {
				builder.append(matrix.get(i).get(j));
				builder.append(' ');
			}
			builder.append('\n');
		}
		
		return builder.toString();
	}
}